package chapter22;

import java.util.*;

public class TestCollectionStaticFunc {

	public static void main(String[] args) {
		
		List<String> list1 = Arrays.asList("yellow", "red", "green", "blue");
		// 对实现Comparable接口的对象    升序   排序
		Collections.sort(list1);
		System.out.println(list1);
		
		// 对实现Comparable接口的对象    降序   排序
		Collections.sort(list1, Collections.reverseOrder());
		System.out.println(list1);
		
		// 二分查找
		List<Integer> list2 = Arrays.asList(2, 4, 7, 10, 11, 45, 50, 59, 60, 66);
		System.out.println("(1) Index: " + Collections.binarySearch(list2, 7));
		System.out.println("(2) Index: " + Collections.binarySearch(list2, 9));
		System.out.println("(3) Index: " + Collections.binarySearch(list1, "red"));
		System.out.println("(4) Index: " + Collections.binarySearch(list1, "cyan"));
		
		//对线性表逆序
		Collections.reverse(list1);
		System.out.println(list1);
		
		//使线性表乱序
		Collections.shuffle(list1);
		System.out.println(list1);
		
		//若指定的相同的Random对象，则会产生一个和原始线性表拥有相同元素序列的线性表
		List<String> list3 = Arrays.asList("yellow", "red", "green", "blue");
		List<String> list4 = Arrays.asList("yellow", "red", "green", "blue");
		Collections.shuffle(list3, new Random(20));
		Collections.shuffle(list4, new Random(20));
		System.out.println(list3);
		System.out.println(list4);
		
		//浅复制线性表
		List<String> list5 = Arrays.asList("white", "black");
		Collections.copy(list4, list5);
		System.out.println(list4);
		
		//创建指定对象n个副本的不可变线性表
		List<GregorianCalendar> list6 = Collections.nCopies(5, new GregorianCalendar(2005, 0, 1));
		System.out.println(list6);
	}

}
